package moc.egg;
import moc.compiler.*;
import moc.tds.*;
import moc.type.*;
import moc.gc.*;
import java.util.*;
import mg.egg.eggc.runtime.libjava.lex.*;
import mg.egg.eggc.runtime.libjava.*;
import mg.egg.eggc.runtime.libjava.messages.*;
import mg.egg.eggc.runtime.libjava.problem.IProblem;
import java.util.Vector;
public class S_FONCTION_MOC {
LEX_MOC scanner;
  S_FONCTION_MOC() {
    }
  S_FONCTION_MOC(LEX_MOC scanner, boolean eval) {
    this.scanner = scanner;
    this.att_eval = eval;
    this.att_scanner = scanner;
    }
int [] sync= new int[0];
  int att_num;
  String att_prelude;
  boolean att_eval;
  String att_code;
  IMachine att_machine;
  TDS att_tds;
  LEX_MOC att_scanner;
  INFOFUN glob_4_info;
  private void regle4() throws Exception {

    //declaration
    S_TYPE_MOC x_2 = new S_TYPE_MOC(scanner,att_eval) ;
    T_MOC x_3 = new T_MOC(scanner ) ;
    T_MOC x_4 = new T_MOC(scanner ) ;
    S_PARFS_MOC x_6 = new S_PARFS_MOC(scanner,att_eval) ;
    T_MOC x_7 = new T_MOC(scanner ) ;
    S_BLOC_MOC x_10 = new S_BLOC_MOC(scanner,att_eval) ;
    //appel
if  (att_eval)      action_auto_inh_4(x_2, x_3, x_6, x_10);
    x_2.analyser() ;
    x_3.analyser(LEX_MOC.token_ident);
    x_4.analyser(LEX_MOC.token_paro);
if  (att_eval)      action_sig_4(x_2, x_3, x_6, x_10);
    x_6.analyser() ;
    x_7.analyser(LEX_MOC.token_parf);
if  (att_eval)      action_tdsBLOC_4(x_2, x_3, x_6, x_10);
if  (att_eval)      action_add2TDS_4(x_2, x_3, x_6, x_10);
    x_10.analyser() ;
if  (att_eval)      action_code_4(x_2, x_3, x_6, x_10);
  }
private void action_auto_inh_4(S_TYPE_MOC x_2, T_MOC x_3, S_PARFS_MOC x_6, S_BLOC_MOC x_10) throws Exception {
try {
// instructions
x_2.att_machine=this.att_machine;
x_6.att_machine=this.att_machine;
x_10.att_machine=this.att_machine;
}catch(RuntimeException e) {       att_scanner._interrompre(IProblem.Internal,att_scanner.getBeginLine(),ICoreMessages.id_EGG_runtime_error, CoreMessages.EGG_runtime_error,new Object[] { "MOC", "#auto_inh","FONCTION -> TYPE ident paro #sig PARFS parf #tdsBLOC #add2TDS BLOC #code ;"});
}
  }
private void action_sig_4(S_TYPE_MOC x_2, T_MOC x_3, S_PARFS_MOC x_6, S_BLOC_MOC x_10) throws Exception {
try {
// instructions
x_6.att_hsignature= new SIGNATURE();
x_6.att_hdepLB=0;
}catch(RuntimeException e) {       att_scanner._interrompre(IProblem.Internal,att_scanner.getBeginLine(),ICoreMessages.id_EGG_runtime_error, CoreMessages.EGG_runtime_error,new Object[] { "MOC", "#sig","FONCTION -> TYPE ident paro #sig PARFS parf #tdsBLOC #add2TDS BLOC #code ;"});
}
  }
private void action_add2TDS_4(S_TYPE_MOC x_2, T_MOC x_3, S_PARFS_MOC x_6, S_BLOC_MOC x_10) throws Exception {
try {
// locales
// instructions
if ((this.att_tds.chercherGlobalementFonction(x_3.att_txt, x_6.att_signature)!=null)){
att_scanner._interrompre(IProblem.Semantic, att_scanner.getBeginLine(), IMOCMessages.id_FonctionExiste, MOCMessages.FonctionExiste,new Object[]{""+x_3.att_txt});

}
else {
if ((x_3.att_txt.equals("main"))){
this.att_prelude="main"+this.att_num;
}
else {
this.att_prelude="";
}
glob_4_info= new INFOFUN(this.att_num, x_2.att_type, x_6.att_signature);
this.att_tds.put(x_3.att_txt+this.att_num, glob_4_info);
x_10.att_tds.put(x_3.att_txt+this.att_num, glob_4_info);
}
}catch(RuntimeException e) {       att_scanner._interrompre(IProblem.Internal,att_scanner.getBeginLine(),ICoreMessages.id_EGG_runtime_error, CoreMessages.EGG_runtime_error,new Object[] { "MOC", "#add2TDS","FONCTION -> TYPE ident paro #sig PARFS parf #tdsBLOC #add2TDS BLOC #code ;"});
}
  }
private void action_tdsBLOC_4(S_TYPE_MOC x_2, T_MOC x_3, S_PARFS_MOC x_6, S_BLOC_MOC x_10) throws Exception {
try {
// locales
TDS loc_tds;
// instructions
loc_tds= new TDS(this.att_tds);
loc_tds.inserer(x_6.att_signature);
x_10.att_tds=loc_tds;
x_10.att_hdep=3;
x_10.att_rtype=x_2.att_type;
x_10.att_targs=-(x_6.att_depLB);
}catch(RuntimeException e) {       att_scanner._interrompre(IProblem.Internal,att_scanner.getBeginLine(),ICoreMessages.id_EGG_runtime_error, CoreMessages.EGG_runtime_error,new Object[] { "MOC", "#tdsBLOC","FONCTION -> TYPE ident paro #sig PARFS parf #tdsBLOC #add2TDS BLOC #code ;"});
}
  }
private void action_code_4(S_TYPE_MOC x_2, T_MOC x_3, S_PARFS_MOC x_6, S_BLOC_MOC x_10) throws Exception {
try {
// instructions
if (x_2.att_type instanceof VOIDTYPE ){
this.att_code=this.att_machine.genComment("Code de "+x_3.att_txt)+this.att_machine.genFonction(x_3.att_txt+this.att_num, x_10.att_code)+this.att_machine.genComment("Retour Void")+this.att_machine.genReturn(((VOIDTYPE)x_2.att_type), -(x_6.att_depLB));
}
else {
if ((x_10.att_ret==true)){
this.att_code=this.att_machine.genComment("Code de "+x_3.att_txt)+this.att_machine.genFonction(x_3.att_txt+this.att_num, x_10.att_code);
}
else {
att_scanner._interrompre(IProblem.Semantic, att_scanner.getBeginLine(), IMOCMessages.id_SANS_RETOUR, MOCMessages.SANS_RETOUR,new Object[]{});

}

}
}catch(RuntimeException e) {       att_scanner._interrompre(IProblem.Internal,att_scanner.getBeginLine(),ICoreMessages.id_EGG_runtime_error, CoreMessages.EGG_runtime_error,new Object[] { "MOC", "#code","FONCTION -> TYPE ident paro #sig PARFS parf #tdsBLOC #add2TDS BLOC #code ;"});
}
  }
  public void analyser () throws Exception {
    regle4 () ;
  }
  }
